// pages/detail/detail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    quanbu: [],
    detail: null,
    zhuimanLists: wx.getStorageSync('zhuimanLists') || [],
    agopageSub: [],
    comment: [],
    morepage: [],
    isCollect: false,
    skeys:'',
    swords:[{img:"XE.png",name:"哈哈哈",}],
    ping:[],
  },
  
  Event(e) {
    this.setData({
      isCollect: !this.data.isCollect,
    })
    if (this.data.isCollect == false) {
      this.setData({
        zhuimanLists: this.data.zhuimanLists.filter((o) => o.id !== e.currentTarget.dataset.id)
      })
      wx.setStorageSync('zhuimanLists', this.data.zhuimanLists)
    }
    wx.showToast({
      title: '已取消收藏',
      icon: 'none',
    })
    if (this.data.isCollect == true) {
      console.log(e.currentTarget.dataset.id);
      this.setData({
        zhuimanLists: [{
          id: e.currentTarget.dataset.id
        }, ...this.data.zhuimanLists],
      })
      wx.setStorageSync('zhuimanLists', this.data.zhuimanLists)
      wx.showToast({
        title: '收藏成功',
        icon: 'none',
      })
    }
  },
  doComment(e){
    this.setData({
      skeys:e.detail.value,
      })
      this.data.ping=[this.data.swords,...this.data.comment]
      // console.log(this.data.swords);
  },
  navToDetail(event) {
    // console.log(event.currentTarget.dataset);
    wx.navigateTo({
      url: `/pages/detail/detail?id=${event.currentTarget.dataset.id}&title=${event.currentTarget.dataset.title}`,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
   
    wx.showLoading({
      title: '加载中',
    })
    console.log(options);
    wx.setNavigationBarTitle({
      title: options.title,
    })
    wx.request({
      url: 'http://cloud.agopage.com/6b83fd3bc06260ec/agopageDetail?',
      data: {
        agopageId: options.id
      },
      success: (res) => {
        this.setData({
          quanbu: res,
          detail: res.data.agopage,
          agopageSub: res.data.agopageSub,
          comment: res.data.comment,
          morepage: res.data.morePage
        })
        this.setData({
          isCollect: (this.data.zhuimanLists.indexOf(this.data.detail.objectId)>-1)?true:false
        })
      },
      complete: () => {
        wx.hideLoading()
      }
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})